package com.etonedu.meals.http.xutils;

import com.etonedu.meals.http.Response;
import com.google.gson.Gson;

import java.lang.reflect.Type;

public class XUtilsResponseImpl implements XUtilsResponse {
    private Response response;
    private Type type;

    public XUtilsResponseImpl() {}

    public XUtilsResponseImpl(Response response, Type type) {
        this.response = response;
        this.type = type;
    }

    @Override
    public void response(String result) {
        Gson gson = new Gson();
        if (response != null) {
            Object o = gson.fromJson(result, type);
            response.callBack(o.toString(),result);
        }
    }

    @Override
    public void error(String msg) {
        if (response != null) {
            response.error(msg);
        }
    }
}
